package com.star.platforms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.star.platforms.common.ResultBean;
import com.star.platforms.dao.StockArticleMapper;
import com.star.platforms.dao.StockColumnMapper;
import com.star.platforms.service.INewsColumn;
import com.star.platforms.vo.CommonPageListVo;
import com.star.platforms.vo.StockArticleVo;
import com.star.platforms.vo.StockNewsColumnVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class StockNewsColumnService implements INewsColumn {
    @Autowired
    StockColumnMapper stockColumnMapper;
    @Autowired
    StockArticleMapper stockArticleMapper;

    @Override
    public ResultBean<List<StockNewsColumnVo>> getNewsColumnList() {
        List<StockNewsColumnVo> data = stockColumnMapper.selectList();
        if(data==null){
            data = new ArrayList<>();
        }
        return new ResultBean<>(200,"成功",data);
    }

    @Override
    public ResultBean<CommonPageListVo<StockArticleVo>> getArticleList(int pageNum) {
        PageHelper.startPage(pageNum,10);
        List<StockArticleVo> list = stockArticleMapper.getArticleList();
        PageInfo<StockArticleVo> pageInfo = new PageInfo<>(list);
        CommonPageListVo<StockArticleVo> data = new CommonPageListVo<>(pageInfo.getPageNum(),pageInfo.getPageSize(),pageInfo.getList());
        return new ResultBean<>(200,"成功",data);
    }


}
